
#include <iostream>

#include "SDL.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"

#include "ddc.h"

#include "contra_resource.h"
#include "contra_scene.h"

int Contra_InitMusicChunks() {
    Mix_Chunk *chunk;
    for (const char *fp: Contra_gAudioResArray) {
        if (!(chunk = Mix_LoadWAV(fp))) {
            std::cerr << "[CONTRA] Contra_LoadMusicChunks(): "
                         "fault: " << Mix_GetError() << std::endl;
            return 1;
        }
        Contra_gMusicChucks.push_back(chunk);
    }
    return 0;
}

int Contra_Init() {
    TTF_Init();
    Dodoco::GetDodocoWithInit(800, 600, 60);

    if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,
                      MIX_DEFAULT_FORMAT,
                      MIX_DEFAULT_CHANNELS, 4096) == -1) {
        std::cerr << "[CONTRA]: Error: Mix_OpenAudio() fault" << std::endl;
        return 1;
    }

    return Contra_InitMusicChunks();
}

int main(int argc, char *argv[]) {
    if (Contra_Init())
        return 1;

    DDC_Scene *introScene;

    if (!(introScene = Contra_IntroSceneCreate()))
        return 1;

    if (!Contra_MenuSceneCreate())
        return 1;

    if (!(Contra_MainGameSceneCreate()))
        return 1;

    if (!(Contra_FailSettlementSceneCreate()))
        return 1;

    if (!(Contra_WinSettlementSceneCreate()))
        return 1;

    Dodoco::GetDodoco()->Run(introScene);
}
